# Create your views here.
from django.http import HttpResponse
import multiprofiles.utils as utils

def change_profile(request):
    profile_type = request.POST['profile_type']
    user = utils.get_user_class().objects.get(pk=request.POST['user_id'])

    OldProfileClass = utils.get_profile_class(user.profile_type)
    old_profiles = OldProfileClass.objects.filter(user__id=user.id)
    old_profiles.delete()
    
    user.profile_type = profile_type
    user.invoke_profile_change = True
    user.save()
      
    return HttpResponse(status=200)